package jrdcom.com.onecodesample.View;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import jrdcom.com.onecodesample.R;

/**
 * Created by longcheng on 17/1/23.
 */
public class CustomTitleBar extends LinearLayout {
    private Button LeftBtn;
    private Button RightBtn;
    private TextView TitleText;
    private TitleBarClickListeter btnClickListeter;
    public CustomTitleBar(Context context) {
        super(context, null);
    }

    public CustomTitleBar(Context context,  AttributeSet attrs) {
        super(context, attrs, 0);
        init(context);
    }

    private  void init(Context context){
        LayoutInflater.from(context).inflate(R.layout.layout_title_bar_1,this);
        LeftBtn = (Button)findViewById(R.id.btn_left);
        RightBtn = (Button)findViewById(R.id.btn_right);
        TitleText = (TextView)findViewById(R.id.text_title);

        LeftBtn.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                btnClickListeter.LeftBtnClick();
            }
        });

        RightBtn.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                btnClickListeter.RightBtnClick();
            }
        });
        TitleText.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                btnClickListeter.TitleClick();
            }
        });
    }

    public void setLeftBtnHide(Boolean show){
        if(true  == show){
            LeftBtn.setVisibility(VISIBLE);
        }else{
            LeftBtn.setVisibility(GONE);
        }
    }

    public void setRightBtnHide(Boolean show){
        if(true == show){
            RightBtn.setVisibility(VISIBLE);
        }else{
            RightBtn.setVisibility(GONE);
        }
    }

    public void setBtnClickListeter(TitleBarClickListeter listeter){
        this.btnClickListeter = listeter;
    }

    //define the click lister
    public interface TitleBarClickListeter{
        void LeftBtnClick();
        void RightBtnClick();
        void TitleClick();
    }

    public void setTitle(String title){
        TitleText.setText(title);
    }


}


